Description

This Rmd will prepare temperature data for inclusion in the model. Much of the code is borrowed from 20_covariate_data.Rmd, but is trimmed down to only what is needed to generate a gap-less temperature dataset.

There is a considerable amount of missing temperature data. To interpolate missing values, we will use the following protocol to determine where temperature data is drawn from:

  1. If tailrace temperature data is available, use tailrace temperature data
  2. If tailrace temperature data is not available but forebay temperature is, use the forebay temperature
  3. If the gap of temperatures is less than one week, linearly interpolate between those two points
  4. If neither is available, use the relationship between temperature at the current dam and temperature at a nearby dam to interpolate (we will determine what that relationship is in this script)
  5. If no dam has available temperature data for the date in question, use a linear interpolation between the last two temperature data points.

Throughout all of this, we will make sure to record how each temperature data point was generated for QA/QC purposes.

Here, we will distinguish between forebay (“f”) and tailrace (“t”) temperature at each dam

plot forebay vs. tailrace temperature

data filtering

there are some complete nonsense values that it looks like we will have to filter. Worst offenders are RIS, RRE, and WEL. Is it the forebay or tailrace temperatures that are bad? Turns out both

filtering function

Two steps: 1. For total nonsense runs of values (RIS, RRE, and WEL) - manually select and drop those days 2. Drop outliers - see chunk below

For outliers: Any values that are +/- 4 degrees away from the long-term mean for that day will be dropped

get the upper columbia dam temperature relationships with Wanapum

Generate the full temperature time series from which to generate windows

calculate windows

export temperature data using window approach